package com.flexycore.iphone.controllers;


import com.flexycore.iphone.uikit.NSIndexPath;
import com.flexycore.iphone.uikit.UIAlertView;
import com.flexycore.iphone.uikit.UIColor;
import com.flexycore.iphone.uikit.UINavigationController;
import com.flexycore.iphone.uikit.UITableView;
import com.flexycore.iphone.uikit.UITableViewCell;
import com.flexycore.iphone.uikit.UITableViewController;
import com.flexycore.iphone.uikit.UITableViewStyle;
import com.flexycore.iphone.uikit.UITextAlignment;

/**
 * 
 * @author matthieu nicolazo
 *
 */
public class MenuController extends UITableViewController {
	/**
	 * Navigation controller containing this view.
	 */
	private UINavigationController nav;
	
	/**
	 * Constructor
	 */
	public MenuController(UINavigationController n){
		super();
		initWithStyle(UITableViewStyle.UITableViewStyleGrouped);
		setTitle("Alert View");
		
		nav = n;
		
		tableView().setBackgroundColor(UIColor.clearColor());
		tableView().setScrollEnabled(false);
	}
	
	/**
	 * @param	tableView		TableView calling this method.
	 */
	//@Override
	public int numberOfSectionsInTableView(UITableView tableView) {
		return 1;
	}
	
	/**
	 * @param	tableView		TableView calling this method.
	 * @param	section			Section index.
	 */
	//@Override
	public int tableViewNumberOfRowsInSection(UITableView table, int section) {
		return 1;
	}
	
	/**
	 * @param	tableView		TableView calling this method.
	 * @param	section			Section index.
	 */
	//@Override
	public float tableViewHeightForHeaderInSection(UITableView tableView, int section) {
		return 20;
	}
	
	/**
	 * Method called by system for displaying UITableViewCell
	 * @param	tableView		TableView calling this method.
	 * @param	indexPath		Row index of cell.
	 */
	//@Override
	public UITableViewCell tableViewCellForRowAtIndexPath(UITableView tableView, 
			NSIndexPath indexPath) {
		UITableViewCell cell = new UITableViewCell();
		cell.init();
		cell.setText("Dialog alert");
		cell.setTextAlignment(UITextAlignment.UITextAlignmentCenter);
		return cell;
	}
	
	/**
	 * Method called by system when user select a row in table view.
	 * @param	tableView		TableView calling this method.
	 * @param	indexPath		Row index of cell.
	 */
	//@Override
	public void tableViewDidSelectRowAtIndexPath(UITableView tableView,
			NSIndexPath indexPath) {
		// Display, in function of cell, an alert view
		UIAlertView alert = new UIAlertView();
		alert.init();
		DeleteAlertDelegate delegate = new DeleteAlertDelegate(this);
		alert.setTitle("Delete e-mails alert");
		alert.setMessage("Do you really want to delete this e-mail ?\nYou will not be able to find it later.");
		alert.setDelegate(delegate);
		alert.addButtonWithTitle("Cancel");
		alert.addButtonWithTitle("Delete e-mail");
		alert.show();
	}
	
	/**
	 * 
	 * @return		The current UINavigationController
	 */
	public UINavigationController getNavigationController(){
		return nav;
	}
	
}
